import request from '/@/utils/request';

export const relationTree = (params?: Object) => {
	return request({
		url: '/ai/relation/tree',
		method: 'get',
		params: params
	});
};

export const addObj = (obj: Object) => {
	return request({
		url: '/ai/relation',
		method: 'post',
		data: obj,
	});
};

export const getObj = (id: string) => {
	return request({
		url: '/ai/relation/' + id,
		method: 'get',
	});
};

export const delObj = (id: string) => {
	return request({
		url: '/ai/relation/' + id,
		method: 'delete',
	});
};

export const putObj = (dataForm?: Object) => {
	return request({
		url: '/ai/relation',
		method: 'put',
		data: dataForm,
	});
};

export const syncUser = () => {
	return request({
		url: '/ai/connect/sync/ding/user',
		method: 'post',
	});
};

export const syncrelation = () => {
	return request({
		url: '/ai/connect/sync/ding/relation',
		method: 'post',
	});
};

export const syncCpUser = () => {
	return request({
		url: '/ai/connect/sync/cp/user',
		method: 'post',
	});
};

export const syncCprelation = () => {
	return request({
		url: '/ai/connect/sync/cp/relation',
		method: 'post',
	});
};

export function dataSource(query?: Object) {
	return request({
		url: '/gen/dsconf/list',
		method: 'get',
		params: query
	})
}

export function fetchTables(datasourceName?: Object) {
	return request({
		url: '/gen/table/list/' + datasourceName,
		method: 'get',
	})
}

export function fetchFields(datasourceName?: Object, tableName?: string) {
	return request({
		url: '/gen/table/' + datasourceName + '/' + tableName,
		method: 'get',
	})
}

export function getRelationshipData(params) {
	return request({
		url: '/ai/relation/graph',
		method: 'get',
		params
	});
}